<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../Styles/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="article-body">

    <div class="article-intro" id="content">

        <h1>Python 3 教程</h1>
        <div class="tutintro">
            <img src="http://www.runoob.com/wp-content/uploads/2014/05/python3.png" alt="python3" width="150"
                 height="81" class="alignnone size-full wp-image-7280">
            <p>Python的3.0版本，常被称为Python 3000，或简称Py3k。相对于Python的早期版本，这是一个较大的升级。为了不带入过多的累赘，Python 3.0在设计的时候没有考虑向下兼容。</p>
            <p>Python 介绍及安装教程我们在<a href="/python/python-tutorial.html" target="_blank">Python 2.X版本的教程</a>中已有介绍，这里就不再赘述。<a>
            </a></p>
            <p><a>你也可以点击</a><a target="_top" href="python-2x-3x.html"> Python2.x与3​​.x版本区别 </a>来查看两者的不同。</p>
            <p>本教程主要针对Python 3.x版本的学习，如果你使用的是Python 2.x版本请移步至<a href="/python/python-tutorial.html" target="_blank">Python
                2.X版本的教程</a>。
            </p>
        </div>
        <p>
        <h2>查看python版本</h2>
        <p>我们可以使用以下命令来查看我们使用的Python版本：</p>
        <pre class="prettyprint prettyprinted" style=""><span class="pln">python </span><span class="pun">-</span><span
                class="pln">V</span></pre>
        <p>以上命令执行结果如下：</p>
        <pre class="prettyprint prettyprinted" style=""><span class="typ">Python</span><span class="pln"> </span><span
                class="lit">3.3</span><span class="pun">.</span><span class="lit">2</span></pre>
        <p>你也可以进入Python的交互式编程模式，查看版本：</p>
        <pre class="prettyprint prettyprinted" style=""><span class="typ">Python</span><span class="pln"> </span><span
                class="lit">3.3</span><span class="pun">.</span><span class="lit">2</span><span
                class="pln"> </span><span class="pun">(</span><span class="pln">v3</span><span class="pun">.</span><span
                class="lit">3.2</span><span class="pun">:</span><span class="pln">d047928ae3f6</span><span
                class="pun">,</span><span class="pln"> </span><span class="typ">May</span><span
                class="pln"> </span><span class="lit">16</span><span class="pln"> </span><span
                class="lit">2013</span><span class="pun">,</span><span class="pln"> </span><span
                class="lit">00</span><span class="pun">:</span><span class="lit">03</span><span
                class="pun">:</span><span class="lit">43</span><span class="pun">)</span><span class="pln"> </span><span
                class="pun">[</span><span class="pln">MSC v</span><span class="pun">.</span><span
                class="lit">1600</span><span class="pln"> </span><span class="lit">32</span><span
                class="pln"> bit </span><span class="pun">(</span><span class="typ">Intel</span><span
                class="pun">)]</span><span class="pln"> on win32
</span><span class="typ">Type</span><span class="pln"> </span><span class="str">"copyright"</span><span
                class="pun">,</span><span class="pln"> </span><span class="str">"credits"</span><span
                class="pln"> </span><span class="kwd">or</span><span class="pln"> </span><span
                class="str">"license()"</span><span class="pln"> </span><span class="kwd">for</span><span class="pln"> more information</span><span
                class="pun">.</span><span class="pln">
</span><span class="pun">&gt;&gt;&gt;</span><span class="pln"> </span></pre>

        <h2>第一个Python3.x程序</h2>
        <p>对于大多数程序语言，第一个入门编程代码便是"Hello World！"，以下代码为使用Python输出"Hello World！"：</p>
        <div class="example">
            <div class="example">实例(Python 3.0+)</div>
            <div class="example_code">
                <pre class="hl-main"><span class="hl-comment">#!/usr/bin/python3</span><span class="hl-code">

</span><span class="hl-identifier">print</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span
                        class="hl-string">Hello, World!</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span
                        class="hl-code">;</span></pre>
            </div>
            <br>
        </div>
        <p>你可以将以上代码保存在hello.py文件中并使用python命令执行该脚本文件。</p>
        <pre class="prettyprint prettyprinted" style=""><span class="pln">$ python3 hello</span><span
                class="pun">.</span><span class="pln">py</span></pre>
        <p>以上命令输出结果为：</p>
        <pre class="prettyprint prettyprinted" style=""><span class="typ">Hello</span><span class="pun">,</span><span
                class="pln"> </span><span class="typ">World</span><span class="pun">!</span></pre>

    </div>
</div>
</body>
</html>
